/**
 * Created by WangMing on 15/12/9.
 */
var avalon = require("./assets/vendor/avalon/avalon.shim");
// require('../node_modules/purecss/build/pure-min.css');
// require('./assets/css/layouts/side-menu.css');
// require('./assets/css/style.css');
require('./assets/css/app.less');
//项目入口

require("./assets/vendor/oniui/mmPromise/mmPromise");
require("./assets/vendor/oniui/scrollbar/avalon.scrollbar");

// require("./assets/vendor/oniui/mmRequest/mmRequest");
// require("./assets/vendor/oniui/mmRouter/mmState");
// require("./assets/vendor/oniui/cookie/avalon.cookie");
// require("./assets/vendor/oniui/datepicker/avalon.coupledatepicker");
// require("./assets/vendor/oniui/pager/avalon.pager");
// require("./assets/vendor/oniui/dialog/avalon.dialog");
// require("./assets/vendor/oniui/validation/avalon.validation");
require("expose?jQuery!jquery");
require("expose?_!lodash");
require("expose?jwplayer!jwplayer");
require("assets/vendor/brocasthelper")
require("assets/vendor/cuehelper")
require("assets/vendor/cueswhelper")
require("expose?qrcode!qrcode");



var config = require("./utils/config");



var i18n = require("./utils/i18n");


    var enumTeachingType = [];
    enumTeachingType.push( i18n.gettext("VIDEO_TEACHINGTYPE_CONVERSATION"));
    enumTeachingType.push( i18n.gettext("VIDEO_TEACHINGTYPE_TRAINING"));
    enumTeachingType.push( i18n.gettext("VIDEO_TEACHINGTYPE_LECTURE"));
    enumTeachingType.push( i18n.gettext("VIDEO_TEACHINGTYPE_BLENDING"));


    config = _.merge({teacherType:enumTeachingType},config);

// var socket = require('engine.io-client')('ws://localhost');
// socket.on('open', function(){
//   socket.on('message', function(data){});
//   socket.on('close', function(){}); 
// });


// require("./widgets/videoslist/videoslist");

// 定义一个顶层的vmodel，用来放置全局共享数据
var root = avalon.define({
    $id: "app",
    $i18n: i18n,
    $sitePath: "", 
    // $sitePath: "http://192.168.2.142",
    
    $images: {
        DefaultLogo: require("./assets/css/images/logo.png"),
        DefaultImg: require("./assets/css/images/DefaultImg_video.png"),
        DefaultImg_album: require("./assets/css/images/DefaultImg_album.png"),
        DefauteUserImg: require("./assets/css/images/DefauteUserImg.png"),
        page_not_found: require("./assets/css/images/page_not_found.png"),
        loading_720_gif: require("./assets/css/images/720.gif"),
        loading_ava_gif: require("./assets/css/images/ava_loading.gif"),
        logoDefaultImg: require("./assets/css/images/logo.png"),
        kankanCode: require("./assets/css/images/pic_code.png")
    },
    currentStateModel: null,
    $skipWatch: ["$i18n", "$images"],

    $lang: {
        speaker: i18n.gettext("speaker"),
        viewCount: i18n.gettext("viewCount"),
        videoCount: i18n.gettext("videoCount"),
        videoinfo: i18n.gettext("video info"),
        keynotelist: i18n.gettext("keynote list"),
        classprogress: i18n.gettext("class progress"),
        videost:i18n.gettext('videoST'),
        comments: i18n.gettext("comments"),
        asksAndQuestions: i18n.gettext("asks and questions"),
        attachments: i18n.gettext("attachments"),
        videoView: i18n.gettext("videoView"),
        favorite: i18n.gettext("favorite"),
        score: i18n.gettext("score"),
        totalScore: i18n.gettext("totalScore"),
        reviews: i18n.gettext("reviews"),
        takeReviews: i18n.gettext("take Reviews"),
        remark: i18n.gettext("remark"),
        category: i18n.gettext("category"),
        classes: i18n.gettext("classes"),
        recordTime: i18n.gettext("recordTime"),
        noResult: i18n.gettext("noResult"),
        mainSpeaker: i18n.gettext("mainSpeaker"),
        joinin: i18n.gettext("join in"),
        techingType: i18n.gettext("techingType"),
        noVideoData : i18n.gettext("no video data"),
        guessYouLike: i18n.gettext("guess you like"), 
        showMore : i18n.gettext("show more"),
        hideMore : i18n.gettext("hide more"),
        moreNotice : i18n.gettext("more notice"),
        albumVideos:i18n.gettext("album videos")
    },
    $config:{
        fileType:{
            0:{
                _class:"ico ic-unknow-icon"
            },
            1:{
                _class:"ico ic-txt-icon" 
            },
            2:{
                _class:"ico ic-office-icon"
            },
            3:{
                _class:"ico ic-rar-icon"
            },
            4:{
                _class:"ico ic-photo-icon"
            }
        }
    }
});


$(window).on("imagesDefault", function(e) {
    $("img").each(function(i, _self) {

        var $self = $(_self),
            img = _self;
        if (img.loaded == undefined) img.loaded = false;
        $self.one("appear", function() {
            if (!img.loaded) {

                $("<img />")
                    .one("load", function() {
                        var original = $self.attr("data-original");
                        $self.attr("src", original);
                        img.loaded = true;

                    }).one("error", function(e) {
                        $(e.target).unbind("load");

                        $("<img />")
                            .one("load", function() {
                                var original = $self.attr("data-original2");
                                $self.attr("src", original);
                                img.original = 2;
                                img.loaded = true;
                            }).one("error",function(e){ 
                                img.original = 2; 
                            }).attr("src", $self.attr("data-original2"));
                    }).attr("src", $self.attr("data-original"));
            }

        })
        if (!img.loaded) {
            $self.trigger("appear")
        }

    }) 
})
$(window).on("resize",function(){
    var h = $(window).height()-82; 
    $('.searchBox,.searchBox>div,.notice-page,.liveRegister-page,.myVideos').css('min-height',h)
})
$('input').on('keydown',function(e){
    console.log('keydown')
    $(this).trigger('blur').trigger('focus')
    // $(this).trigger('change')
})

avalon.config({ debug: true })


var routers = require("./routers");

/**
 * 路由全局配置
 */
avalon.state.config({
    onError: function() {
        // console.log(arguments)
    },
    onBegin: function() {
        // console.log(arguments);
        // console.log("arguments",arguments)
        // $(function(){
        //     $("html, body").animate({scrollTop: 1});
        
        // })

        var path = arguments[1].path.split("#");



        root.currentStateModel = arguments[1];
        if(path[1]!=undefined){
            location.hash = path[0];
            location.reload()
        }

    },
    onViewEnter: function(newNode, oldNode) {
        // console.log(newNode,oldNode)
            // console.log("onViewEnter",newNode,oldNode);
        } // 不建议使用动画，因此实际使用的时候，最好去掉onViewEnter和ms-view元素上的oni-mmRouter-slide

});
avalon.history.start({
    basepath: "/",
    fireAnchor: false
});

//开始扫描编译
avalon.scan();
